<template>
  <div id="app">
    <mt-header fixed :title="$route.meta.title">
      <span slot="left" @click="goBack" v-show="showBack">
        <mt-button icon="back">返回</mt-button>
      </span>
    </mt-header>

    <router-view></router-view>

    <tabbar></tabbar>
  </div>
</template>

<script>
import tabbar from "./components/tabbar.vue";

export default {
  components: { tabbar },
  name: "App",
  data() {
    return {
      showBack: false,
    };
  },
  created() {
    this.showBack = this.$route.path !== "/home";
      this.checkLogin()
  },
  watch: {
    "$route.path"(newVal) {
      this.showBack = newVal !== "/home";
    },
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
     checkLogin() {
    this.$indicator.open({
      text: '加载中'
    })
    this.$http.get('user').then(res => {
      if (res.data.code === 1) {
        this.$store.commit('user/setUser', res.data.data)
      }
      this.$indicator.close()
    })
  }
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
